1 module hunt.cache.cache; 2 3 import hunt.cache.nullable; 4 import hunt.cache.l2cache; 5 6 final class Cache(T) 7 { 8 9 Nullable!V get_ex(V)(string key) 10 { 11 if(_t !is null) 12 return _t.get!V(key); 13 else 14 return _t2.get!V(key); 15 } 16 17 V get(V)(string key) 18 { 19 return cast(V)get_ex!V(key); 20 } 21 22 Nullable!V[string] getall(V)(string[] keys) 23 { 24 if(_t !is null) 25 return _t.getall!V(keys); 26 else 27 return _t2.getall!V(keys); 28 } 29 30 bool containsKey(string key) 31 { 32 if(_t !is null) 33 return _t.containsKey(key); 34 else 35 return _t2.containsKey(key); 36 } 37 38 void put(V)(string key , V v , uint expired = 0) 39 { 40 if(_t !is null) 41 return _t.put!V(key , v , expired); 42 else 43 return _t2.put!V(key , v , expired); 44 } 45 46 bool putifAbsent(V)(string key , V v) 47 { 48 if( _t !is null) 49 return _t.putifAbsent!V(key , v); 50 else 51 return _t2.putifAbsent!V(key , v); 52 } 53 54 void putAll(V)( V[string] maps , uint expired = 0) 55 { 56 if(_t !is null) 57 return _t.putAll!V(maps , expired); 58 else 59 return _t2.putAll!V(maps , expired); 60 } 61 62 bool remove(string key) 63 { 64 if(_t !is null) 65 return _t.remove(key); 66 else 67 return _t2.remove(key); 68 } 69 70 void removeAll(string[] keys) 71 { 72 if(_t !is null) 73 return _t.removeAll(keys); 74 else 75 return _t2.removeAll(keys); 76 } 77 78 void clear() 79 { 80 if(_t !is null) 81 return _t.clear(); 82 else 83 return _t2.clear(); 84 } 85 86 this(string args , bool enableL2Cache ) 87 { 88 if(enableL2Cache) 89 _t2 = new L2Cache!T(args); 90 else 91 _t = new T(args); 92 } 93 94 private: 95 96 T _t; 97 L2Cache!T _t2; 98 }